package operator;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -03 -26
 * Time: 20:57
 */
public class DelOperator implements Operator{
    @Override
    public void process(BookList booklist) {
        //查找
        Scanner sc=new Scanner(System.in);
        System.out.print("Please input the name of book what you want to delete：");
        String name=sc.nextLine();
        int i=0;
        for(;i< booklist.getSize();i++){
            if(booklist.getBooks(i).getName().equals(name)){
                break;
            }
        }
        if(i== booklist.getSize()){
            System.out.println("can't find the book...");
            return;
        }
        //删除
        for(int index=i+1;index< booklist.getSize();index++){
            booklist.setBooks(index-1,booklist.getBooks(index));
        }
        booklist.setBooks(booklist.getSize(), null);
        booklist.setSize(booklist.getSize()-1);
        System.out.println("delete the book success!");
    }
}
